package com.atguigu.guli.service.edu.controller.admin;


import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.edu.entity.Video;
import com.atguigu.guli.service.edu.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2021-07-26
 */
@Api(tags = "课时管理")

@RestController
@RequestMapping("/admin/edu/video")
@Slf4j
public class AdminVideoController {
    @Autowired
    VideoService videoService;

    @ApiOperation("新增课时")
    @PostMapping("save")
    public R save(@RequestBody Video video){
        boolean b = videoService.save(video);
        if (b){
            return R.ok().message("新增课时成功");
        }else{
            return R.error().message("新增课时失败");
        }
    }

    @ApiOperation("根据id查询课时")
    @GetMapping("getById/{id}")
    public R getById(@PathVariable String id){
        Video video = videoService.getById(id);
        return R.ok().data("item",video);

    }
    @ApiOperation("更新课时")
    @PutMapping("update")
    public R update(@RequestBody Video video){
        System.out.println(video.getId());
        boolean b = videoService.updateById(video);
        if (b){
            return R.ok().message("更新成功");
        }else{
            return R.error().message("更新失败");
        }
    }

    @ApiOperation("删除课时")
    @DeleteMapping("remove/{id}")
    public R removeById(@PathVariable String id){
        boolean b = videoService.removeById(id);
        if (b){
            return R.ok().message("删除成功");
        }else{
            return R.error().message("删除失败");
        }
    }
}

